package org.newcih.service.impl;

import org.newcih.dao.IOrderDao;
import org.newcih.domain.Order;
import org.newcih.service.IOrderService;
import org.omg.IOP.IOR;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class OrderService {

    @Autowired
    private IOrderDao orderDao;

    public Order findByQuery(String id) {
        return orderDao.findByQuery(id);
    }

    public void save(Order order) {
        Optional.ofNullable(order).ifPresent(orderDao::save);
    }

    public void delete(Order order) {
        Optional.ofNullable(order).ifPresent(orderDao::delete);
    }

    public void delete(String id) {
        Optional.ofNullable(id).ifPresent(orderDao::deleteByQuery);
    }

    public Order findById(String id) {
        return orderDao.findById(id);
    }

    public Order findByOrderNumber(Integer number) {
        return orderDao.findByOrderNumber(number);
    }

    public List<Order> findAll() {
        return (List<Order>) orderDao.findAll();
    }

    public Page<Order> findAll(Pageable pageable) {
        return orderDao.findAll(pageable);
    }

    public List<Order> findByIdLike(String idLike) {
        return null;
    }


}
